package com.childenglish.controller;

import com.childenglish.service.RecommendationService;
import com.childenglish.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/recommendation")
public class RecommendationController {

    @Autowired
    private RecommendationService recommendationService;

    /**
     * 获取内容推荐
     */
    @GetMapping("/content/{userId}")
    public R getContentRecommendations(
            @PathVariable Long userId,
            @RequestParam(defaultValue = "beginner") String level) {
        try {
            List<Map<String, Object>> recommendations =
                    recommendationService.recommendContent(userId, level);
            return R.ok("获取推荐内容成功").data(recommendations);
        } catch (Exception e) {
            return R.error("获取推荐内容失败: " + e.getMessage());
        }
    }

    /**
     * 获取个性化推荐
     */
    @GetMapping("/personalized/{userId}")
    public R getPersonalizedRecommendations(@PathVariable Long userId) {
        try {
            List<Map<String, Object>> recommendations =
                    recommendationService.getPersonalizedRecommendations(userId);
            return R.ok("获取个性化推荐成功").data(recommendations);
        } catch (Exception e) {
            return R.error("获取个性化推荐失败: " + e.getMessage());
        }
    }
}